package com.hw.weathershow.observer;


import com.hw.weathershow.entity.Weather;
import com.hw.weathershow.util.ResponseJson;
import com.hw.weathershow.websocket.UpdateWeatherSocket;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

/**
 * The type Weather observer.
 *
 * @author Cejay1314
 * @version 1.0
 * @create 2022 /12/6 15:35
 */
@AllArgsConstructor
@NoArgsConstructor
public class WeatherObserver implements Observer {
    /**
     * The Update weather socket.
     */
    UpdateWeatherSocket updateWeatherSocket;
    /**
     * The Weather.
     */
    public Weather weather;

    @Override
    public void update() {
        String responseJson = new ResponseJson().success()
                .setData("city", weather.getCity())
                .setData("province", weather.getProvince())
                .setData("weather", weather.getWeather())
                .setData("temperature", weather.getTemperature())
                .setData("windDirection", weather.getWindDirection())
                .setData("windPower", weather.getWindPower())
                .setData("humidity", weather.getHumidity())
                .toString();

        updateWeatherSocket.updateWeather(responseJson);
    }

    /**
     * Instantiates a new Weather observer.
     *
     * @param weather the weather
     */
    public WeatherObserver(Weather weather) {
        this.weather = weather;
    }
}
